﻿namespace ApplicationFrame.EntityFrameworkCore.Core
{
    /// <summary>
    /// 范围分表每个分表的区间大小（如10000表示1-10000放第一个表）
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class RangeShardingAttribute : Attribute
    {
        /// <summary>
        /// 每个分表的区间大小（如100000表示1-100000放第一个表）
        /// </summary>
        public long RangeSize { get; }

        /// <summary>
        /// 分表实体属性名称
        /// </summary>
        public string ShardingProperty { get; }

        public RangeShardingAttribute(string shardingProperty, long rangeSize = 100000)
        {
            if (string.IsNullOrWhiteSpace(shardingProperty))
                throw new ArgumentNullException(nameof(shardingProperty));
            ShardingProperty = shardingProperty;
            if (rangeSize <= 0)
                throw new ArgumentException("区间大小必须大于0", nameof(rangeSize));
            RangeSize = rangeSize;
        }
    }
}
